package org.traffometer.traffobase.control.command;


import javax.servlet.http.HttpServletRequest;

import org.traffometer.traffobase.control.Page;
import org.traffometer.traffobase.model.StackModel;

/**
 * Implements the "Clear" command by clearing the stack instance.
 *
 * @author Jitender Miglani
 * @author Philip Johnson
 */
public class ClearCommand implements Command {

  /**
   * Processes the "Clear" command sent by the user.
   * Sets the stackIterator attribute with the resulting stack contents.
   *
   * @param request The request object.
   * @return The page to be displayed (Page.INDEX).
   */
  public Page process(HttpServletRequest request) {
    StackModel stackModel = StackModel.getInstance();
    stackModel.clearStack();
    request.setAttribute("stackIterator", stackModel.iterator());
    return Page.INDEX;
  }
}
